{% extends "element/saas/base_mini.html" %}

{% block meta_title %}多点关联{% endblock %}

{% block extra_css %}
    {{ block.super }}
    <link href="{{ STATIC_URL }}{{ "opensource/jquery/css/jquery.range.css" }}"
          rel="stylesheet" type="text/css"/>
{% endblock %}

{% block main %}
    <style>
        .mini-radiobuttonlist table label {
            vertical-align: initial;
        }
        .mini-tree-expand .mini-tree-folder, .mini-tree-folder {
            background-image: url("/static/element/report/tupu/img/icon.png");
            background-size: 16px auto;
        }
        .treeicon1 {
        {#            个人#} background-image: url("/static/element/report/tupu/img/icon1.png");
            background-size: 14px auto;
        }
        .treeicon2 {
        {#            个体户#} background-image: url("/static/element/report/tupu/img/icon2.png");
            background-size: 14px auto;
        }
        .treeicon3 {
        {#            企业#} background-image: url("/static/element/report/tupu/img/icon3.png");
            background-size: 14px auto;
        }
        .treeicon4 {
        {#            向下箭头#} background-image: url("/static/element/report/tupu/img/icon4.png");
            background-size: 18px auto;
        }
        .treeicon5 {
        {#            向上箭头#} background-image: url("/static/element/report/tupu/img/icon5.png");
            background-size: 18px auto;
        }
    </style>
    <div class="admin-content">
        <div id="toolbar1" class="mini-toolbar" style="padding: 2px 0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button mini-button-eltext" iconCls="icon-chart_org_inverted" plain="true">多点关联分析系统</a>
                        <span class="separator"></span>
                        <a class="mini-button" iconCls="icon-report10" plain="true" onclick="elreport('10')">全景版征信报告</a>
                        <a class="mini-button" iconCls="icon-report11" plain="true" onclick="elreport('11')">标准版报告</a>
                        <a class="mini-menubutton" iconCls="icon-pdf" plain="true" menu="#popupMenu3">下载报告PDF</a>
                        <a class="mini-button" iconCls="icon-feed_add" plain="true" onclick="">关注该企业</a>
                        {# 暂时只对内部的人开放 #}
                        {% if request.user.id < 42 %}
                            <a class="mini-button" iconCls="icon-excel" plain="true"
                               onclick="downloadSure()">导出结果为Excel</a>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>

        <ul id="popupMenu3" class="mini-menu" style="display:none;">
            <li iconCls="icon-pdf" onclick="elreportpdf('10')">全景版PDF</li>
            <li iconCls="icon-pdf" onclick="elreportpdf('11')">标准版PDF</li>
        </ul>

        <div style="padding-top:6px;">
            <div class="min-panel" style="float:left;width:100%;">
                <div id="mainTabs" class="mini-tabs" activeIndex="0" arrowPosition="side" showNavMenu="true"
                     height="auto">
                    <div title="多点关联搜索条件" name="主数据表" iconCls="icon-zoomin" height="auto">
                        {% include "element/saas/related/related_multi_search.html" %}
                    </div>
                    <div title="可视化关联图谱" name="可视化关联图谱" iconCls="icon-chart_line" height="auto"></div>
                    <div title="搜索结果详情" name="搜索结果详情" iconCls="icon-table" height="auto">
                        {% include "element/saas/related/related_multi_treetable.html" %}
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block footer_js %}
    <script src="{{ STATIC_URL }}{{ "opensource/jquery/js/jquery.range.js" }}" type="text/javascript"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/Blob.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/FileSaver.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/xlsx.full.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.slider-input').jRange({
                from: 4,//开始于
                to: 11,//结束于
                step: 1,//一次滑动多少
                {#                scale: [4, 10],//分割点#}
                format: '%s',//格式化格式
                width: 300,//宽度
                showLabels: true,
                showScale: false,
                theme: "theme-blue"
            });
        });
        var comName1 = "", comEid1 = "", comName2 = "", comEid2 = "";
        var se_type = [
            {'value': '1', 'text': '企业（名称）'},
            {'value': '2', 'text': '企业（注册号）'},
            {'value': '3', 'text': '个人（身份证号）'},
            {'value': '4', 'text': '个人（姓名+公司名称）'}
        ];
        mini.parse();
        var tabs = mini.get("mainTabs");
        var tab = tabs.getTab("可视化关联图谱");
        var tab1 = tabs.getTab("搜索结果详情");
        var form_search = new mini.Form("se_form");
        var grid_main = mini.get("datagrid_main");
        tabhei(tab);
        tabhei(tab1);

        top["win"] = window;
        {#        #}
        var radioval = 1, radioval1 = 1, startid, endid;
        var selecttype = mini.get("selecttype");
        selecttype.on("valuechanged", function (e) {
            $("#se_table .selecttype").hide();
            radioval = this.getValue();
            switch (radioval) {
                case "1":
                    showbox("combox1");
                    break;
                case "2":
                    showbox("combox2");
                    break;
                case "3":
                    showbox("personbox1");
                    break;
                case "4":
                    showbox("personbox2");
                    break;
            }
        });
        var selecttype1 = mini.get("selecttype1");
        selecttype1.on("valuechanged", function (e) {
            $("#se_table .selecttype1").hide();
            radioval1 = this.getValue();
            switch (radioval1) {
                case "1":
                    showbox("combox11");
                    break;
                case "2":
                    showbox("combox21");
                    break;
                case "3":
                    showbox("personbox11");
                    break;
                case "4":
                    showbox("personbox21");
                    break;
            }
        });
        function showbox(id) {
            $("#" + id).show();
        }

        {#company1#}
        function startcom(e) {
            var item = e.selected;
            if (item) {
                comEid1 = item.id;
                comName1 = item.text;
            } else {
                comEid1 = "";
                comName1 = "";
            }
        }

        {#company2#}
        function endcom(e) {
            var item = e.selected;
            if (item) {
                comEid2 = item.id;
                comName2 = item.text;
            } else {
                comEid2 = "";
                comName2 = "";
            }
        }

        {#reset#}
        $("#clearbtn").click(function () {
            $("#errorText").hide();
            $("#errorText1").hide();
            form_search.reset();
        });
        var selectVal = "", selectVal1 = "", Nval = -1, Nval1 = -1;

        function formValid() {
            getVal();
            if (Nval > 0 && Nval1 > 0) {
                var val = radioval + "&selectVal=" + selectVal;
                ajax("errorText", val);
                var val1 = radioval1 + "&selectVal=" + selectVal1;
                ajax("errorText1", val1);
            }
        }
        function ajax(id, Nval) {
            var obj = $("#" + id);
            $.ajax({
                url: "/saas/related_node_check/?ntype=" + Nval,
                type: "POST",
                async: false,
                success: function (response) {
                    var msg = response.msg;
                    var st = response.status;
                    if (st == "success") {
                        obj.hide();
                        if (id == "errorText") {
                            startid = msg;
                        } else {
                            endid = msg;
                        }
                        return true;
                    } else {
                        obj.show();
                        if (msg == "") {
                            obj.find(".errorText").html("没有找到相关主体");
                        } else {
                            obj.find(".errorText").html(msg);
                        }
                        return false;
                    }
                }
            });
        }

        function getVal() {
            if (radioval == 1) {
                selectVal = mini.getbyName("ENTNAME").getValue();
            }
            if (radioval == 2) {
                selectVal = mini.getbyName("REGNO").getValue();
            }
            if (radioval == 3) {
                selectVal = mini.getbyName("CERNO").getValue();
            }
            if (radioval == 4) {
                selectVal = mini.getbyName("ENTNAME1").getValue() + "￥￥￥" + mini.getbyName("PNAME").getValue();
            }
            if (radioval1 == 1) {
                selectVal1 = mini.getbyName("ENTNAME2").getValue();
            }
            if (radioval1 == 2) {
                selectVal1 = mini.getbyName("REGNO1").getValue();
            }
            if (radioval1 == 3) {
                selectVal1 = mini.getbyName("CERNO1").getValue();
            }
            if (radioval1 == 4) {
                selectVal1 = mini.getbyName("ENTNAME3").getValue() + "￥￥￥" + mini.getbyName("PNAME1").getValue();
            }
            if (selectVal == "" || selectVal == "￥￥￥") {
                $("#errorText").show();
                $("#errorText .errorText").html("填写内容不能为空");
                Nval = -1;
            } else {
                $("#errorText").hide();
                Nval = 1;
            }
            if (selectVal1 == "" || selectVal1 == "￥￥￥") {
                $("#errorText1").show();
                $("#errorText1 .errorText").html("填写内容不能为空");
                Nval1 = -1;
            } else {
                $("#errorText1").hide();
                Nval1 = 1;
            }
        }
        {#        //tab height#}
        function tabhei(tab) {
            tab.onload = function () {
                var iframe = tabs.getTabIFrameEl(tab);
                var hei = iframe.contentWindow.document.body.scrollHeight + 150;
                iframe.style.height = hei + 'px';
            };
        }
        {#search#}
        function Adsearch() {
            formValid();
            var depth = $(".slider-input").val();
            var n1 = $("#errorText").css("display") == "none",
                    n2 = $("#errorText1").css("display") == "none";
            if (n1 && n2) {
                form_search.validate();
                if (form_search.isValid() == false) return;
                var url = '/saas/related_road/?ntype1=' + radioval + "&pk1=" + startid + "&ntype2=" + radioval1 + "&pk2=" + endid + "&depth=" + depth;
                tabs.loadTab(url, tab);
                tabs.activeTab(tab);
            }
        }

        function elreport(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择搜索结果中的一个企业");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                if (entid_value) {
                    var entname_value = grid_main.getSelected().nodename;
                    newtab("报告: " + entname_value, '/report/' + entid_value + '/?version=' + a, 'icon-report' + a);
                }
                else {
                    mini.alert("请选择搜索结果中的一个企业");
                }
            }
        }

        function elreportpdf(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择搜索结果中的一个企业");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                if (entid_value) {
                    window.open("/reportpdf/" + entid_value + '/?version=' + a);
                }
                else {
                    mini.alert("请选择搜索结果中的一个企业");
                }
            }
        }
        {#    excel#}
        {#联动子级和父级选择#}
        grid_main.on("nodecheck", function (e) {
            if (e.checked) {
                checkrodrnode(e);
            } else {
                checkrodrnode(e, "checked");
            }
        });
        function checkrodrnode(e, check) {
            var _this = e.node,
                    _rowname = _this.rowname,
                    _rownum = _rowname.indexOf("路径-"),
                    _parent = grid_main.getParentNode(_this);
            if (_parent && _rownum < 0) {
                var _childern = grid_main.getChildNodes(_parent);
                if (check) {
                    grid_main.checkNodes(_childern);
                } else {
                    grid_main.uncheckNodes(_childern);
                }
            }
        }
        // 页面json数据生成excel表
        function downloadSure() {
            tabs.setActiveIndex(2);
            var data = grid_main.getList();
            if (!data.length) {
                mini.alert("请重新输入搜索条件~");
                tabs.setActiveIndex(0);
            } else {
                var dataval = grid_main.getCheckedNodes();
                if (dataval.length) {
                    JSONToExcelConvertor(dataval);
                } else {
                    mini.alert("请选择要下载的路径~");
                }
            }
        }
        function JSONToExcelConvertor(JSONData) {
            var FileName = "多点关联筛查结果-{{ sitesettings.website_name }}-" + gettime();
            //先转化json
            var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
            var headers = {
                "roadid": "路径序号",
                "rowname": "路径类型",
                "nodename": "节点名称",
                "conam": "投资金额",
                "conprop": "投资比例",
                "position": "职位",
                "lerepsign": "是否法人",
                "sex": "个人性别",
                "regionid": "企业所在地",
                "nicid": "企业行业",
                "regcap": "企业注册资金(万)",
                "status": "企业状态",
                "esdate": "企业开业日期"
            };
            var arrKey = ["roadid", "rowname", "nodename", "conam", "conprop", "position", "lerepsign", "sex", "regionid", "nicid", "regcap", "status", "esdate"];
            if (arrData[0]["rowname"] != "路径类型") {
                arrData.unshift(headers);
            }
            if (isIEexcel()) {
                exportExcelIE(arrData, arrKey, FileName);
            } else {
                downloadExl(arrData, arrKey, FileName);
            }
        }
    </script>
    {{ block.super }}
{% endblock %}
